<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<jsp:include page="../../header.jsp" />
<div class="content-header">
    <h2 class="content-title">工资管理</h2>
    <div class="action-buttons">
        <a href="salary?action=new" class="btn btn-primary">
            <i class="icon-add"></i> 添加工资记录
        </a>
    </div>
</div>

<div class="filters">
    <form action="salary" method="get" class="filter-form">
        <input type="hidden" name="action" value="filter">
        <div class="filter-row">
            <div class="filter-group">
                <label>月份:</label>
                <select name="month">
                    <option value="">所有月份</option>
                    <c:forEach var="i" begin="1" end="12">
                        <option value="${i}" ${param.month == i ? 'selected' : ''}>
                                ${i}月
                        </option>
                    </c:forEach>
                </select>
            </div>

            <div class="filter-group">
                <label>年份:</label>
                <select name="year">
                    <option value="">所有年份</option>
                    <c:forEach var="i" begin="2020" end="2030">
                        <option value="${i}" ${param.year == i ? 'selected' : ''}>
                                ${i}年
                        </option>
                    </c:forEach>
                </select>
            </div>

            <div class="filter-group">
                <label>状态:</label>
                <select name="status">
                    <option value="">所有状态</option>
                    <option value="已发放" ${param.status == '已发放' ? 'selected' : ''}>已发放</option>
                    <option value="未发放" ${param.status == '未发放' ? 'selected' : ''}>未发放</option>
                </select>
            </div>

            <button type="submit" class="btn btn-search">
                <i class="icon-filter"></i> 筛选
            </button>
        </div>
    </form>
</div>

<div class="card">
    <div class="card-body">
        <table class="data-table">
            <thead>
            <tr>
                <th>工资单号</th>
                <th>员工</th>
                <th>部门</th>
                <th>基本工资</th>
                <th>奖金</th>
                <th>扣除</th>
                <th>实发工资</th>
                <th>发放月份</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach var="salary" items="${salaries}">
                <tr>
                    <td>SL-${salary.id}</td>
                    <td>
                        <div class="employee-info">
                            <div class="avatar">
                                <c:choose>
                                    <c:when test="${salary.employeeGender == '男'}">
                                        <i class="icon-male"></i>
                                    </c:when>
                                    <c:otherwise>
                                        <i class="icon-female"></i>
                                    </c:otherwise>
                                </c:choose>
                            </div>
                            <div class="details">
                                <strong>${salary.employeeName}</strong>
                                <div class="position">${salary.employeePosition}</div>
                            </div>
                        </div>
                    </td>
                    <td>${salary.departmentName}</td>
                    <td>¥ ${salary.baseSalary}</td>
                    <td>¥ ${salary.bonus}</td>
                    <td>¥ ${salary.deduction}</td>
                    <td><strong>¥ ${salary.totalSalary}</strong></td>
                    <td>${salary.paymentMonth}</td>
                    <td>
                        <c:choose>
                            <c:when test="${salary.status == '已发放'}">
                                <span class="status paid">${salary.status}</span>
                            </c:when>
                            <c:otherwise>
                                <span class="status pending">${salary.status}</span>
                            </c:otherwise>
                        </c:choose>
                    </td>
                    <td>
                        <div class="actions">
                            <a href="salary?action=edit&id=${salary.id}" class="btn-action btn-edit" title="编辑">
                                <i class="icon-edit"></i>
                            </a>
                            <c:if test="${salary.status == '未发放'}">
                                <a href="salary?action=pay&id=${salary.id}"
                                   class="btn-action btn-pay" title="发放工资"
                                   onclick="return confirm('确定要发放该工资吗？')">
                                    <i class="icon-pay"></i>
                                </a>
                            </c:if>
                        </div>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>

        <div class="summary">
            <div class="summary-item">
                <span>总记录数:</span>
                <strong>${salaries.size()}</strong>
            </div>
            <div class="summary-item">
                <span>工资总额:</span>
                <strong>¥ ${totalSalaryAmount}</strong>
            </div>
            <div class="summary-item">
                <span>已发放:</span>
                <strong>${paidCount} 人</strong>
            </div>
            <div class="summary-item">
                <span>待发放:</span>
                <strong>${pendingCount} 人</strong>
            </div>
        </div>
    </div>
</div>
<jsp:include page="../../footer.jsp" />